//
//  _008_DemoTableviewViewController.m
//  1008_DemoTableview
//
//  Created by qianfeng on 11-10-7.
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import "_008_DemoTableviewViewController.h"

@implementation _008_DemoTableviewViewController
@synthesize myTableView;



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[myTableView release];
    [super dealloc];
}
/*要画的表到底有几行*/

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
	return 20;
}

/*每一行内容*/
-(UITableViewCell *) tableView:(UITableView *)tableView
		  cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int section = [indexPath section];
	int row = [indexPath row];
	
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableCell"];
	if (cell == nil) {
		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
									  reuseIdentifier:@"MyTableCell"];
		[cell autorelease];
	}
	NSString * str = [NSString stringWithFormat:@"第%d章", row + 1 + section * 20];
	cell.textLabel.text = [NSString stringWithString:str];
	
	if (row % 2 == 0) {
		
	
		//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
	} else {
		cell.selectionStyle = UITableViewCellSelectionStyleGray;
	}

		
	return cell;
}
/*section count*/
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
	return 2;
}

- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
	if (section == 0) {
		return @"上部份";
	}
	else if(section == 1) {
		return @"下部份";
	}
	
	else {
		return @"none";
	}
}

-(void) tableView:(UITableView *)tableView
		didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSString * str = [NSString stringWithFormat:
					  @"section %d row %d",
					  [indexPath section],
					  [indexPath row]];
	UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
	/*get tableView indexPath(section, row) 
	 
	 */
	NSString * str2 = cell.textLabel.text;
	NSLog(@"%@", str);
	NSLog(@"%@", str2);
	

	UIAlertView * av = [[UIAlertView alloc] initWithTitle:str
												  message:str2
												 delegate:self
										cancelButtonTitle:@"yes"
									    otherButtonTitles:@"no",
						nil];
	[av show];
	[av release];
}






@end
